package com.boonya.lab.rpc.client;

import com.boonya.protobuf.grpc.WebSiteGrpc;
import com.boonya.protobuf.grpc.WebSiteDefinition;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * @author Pengjunlin
 * @date 2024/12/28
 */
@Service
public class WebSiteClientImpl implements WebSiteClient {

    //@GrpcClient("proto-server") // 这里拿不到nacos管理的实例，暂时采用手动配置
    @Qualifier("webSiteBlockingStub")
    @Autowired
    private WebSiteGrpc.WebSiteBlockingStub webSiteBlockingStub;

    @Override
    public WebsiteResponse getHttpWebsite(AreaReq areaReq) {
        WebSiteDefinition.AreaReq req = WebSiteDefinition.AreaReq.newBuilder().setAreaCode(areaReq.getCode()).build();
        WebSiteDefinition.HttpWebsiteResp httpWebsiteResp = webSiteBlockingStub.getHttpWebsite(req);

        return WebsiteResponse.builder()
                .code(httpWebsiteResp.getCode())
                .message(httpWebsiteResp.getMessage())
                .data(httpWebsiteResp.getData())
                .build();
    }
}
